import { defineComponent } from "vue";
import { ButtonProps } from "./types";
import clsx from "clsx";
import "./index.less";
import * as vant from "vant";
import { useRouter } from "vue-router";
import { toChatDetail } from "@/command/navigation";
const { showFailToast } = vant;

export default defineComponent({
  name: "button-view",
  props: ButtonProps,
  emits: ["click"],
  setup(_, { slots, emit }) {
    return () => {
      const router = useRouter();
      const classNames = clsx({
        button: true,
        "button-default": _.type == "default",
        "button-primary": _.type == "primary",
        "!w-full": _.block,
      });
      return (
        <div
          class={[
            "w-[70px] h-[30px] flex items-center justify-center cursor-pointer text-[12px]",
            classNames,
          ]}
          onClick={(e) => {
            e.stopPropagation();
            e.preventDefault();
            if (_.toChatData && _.toChatData.to) {
              toChatDetail({
                to: _.toChatData.to,
                name: _.toChatData.name,
              });
              return;
            }
            // if (_.text.includes("联系") || _.text.includes("咨询")) {
            //   router.push("/serviceTim");
            //   // showFailToast("功能暂未开放");
            // }
            emit("click");
          }}
        >
          {_.text ? _.text : slots.default?.()}
        </div>
      );
    };
  },
});
